// JavaScript Document
var CeshiTip = new Object();

CeshiTip.changeDate = function () {
	var date_size = 31;
	var str = "";
	var month_date_value = parseInt(document.getElementById("month_date").value);
	if (month_date_value == 4 || month_date_value == 6 || month_date_value == 9 || month_date_value == 11) {
		date_size = 30;
	}
	if (document.getElementById("month_date").value == 2) {
		if (isLeapyear(document.getElementById("year_date").value)) {
			date_size = 29;
		} else {
			date_size = 28;
		}
	}
	document.getElementById("day_date").options.length = 0;
	for (var i = 1; i <= date_size; i++) {
		document.getElementById("day_date").options.add(new Option("" + i, "" + i)); 
           //str+=("<option value='"+i+"'>"+i+"</option>");
	}
}
/**
  *计算是否闰年
  */
function isLeapyear(date1) {
	return (0 == date1 % 4 && ((date1 % 100 != 0) || (date1 % 400 == 0)));
}

//判断日期的合法性，如果合法就跳转
CeshiTip.checkgoto = function (flag) {
     //如果非注册用户
	 var from=document.getElementById("fb_test").value;	
	if (flag == 1) {
		var input_date_str = document.getElementById("year_date").value + "-" + document.getElementById("month_date").value + "-" + document.getElementById("day_date").value;
		var input_date = Date.parse(input_date_str);
		{
			window.open("http://abc.yaolan.com/ceshi/babytest.action?birthday=" + document.getElementById("year_date").value + "-" + document.getElementById("month_date").value + "-" + document.getElementById("day_date").value+"&from="+from);
		}
	}else if(flag == 3) {
		if(document.getElementById("year_date").value == "" || document.getElementById("month_date").value == ""|| document.getElementById("day_date").value == ""){
			alert("请选择宝宝出生年月日！");
			return ;
		}
		
		var input_date_str = document.getElementById("year_date").value + "-" + document.getElementById("month_date").value + "-" + document.getElementById("day_date").value;
		
		
		var currDate = new Date();
		var currYear = currDate.getFullYear();
		var currMonth = currDate.getMonth();
		var currDay = currDate.getDate();
			
		var input_date =new Date(input_date_str);
		var selectYear = input_date.getFullYear();
		var selectMonth = input_date.getMonth();
		var selectDay = input_date.getDate();

		var month = 0;
		month += (currYear-selectYear)*12;
		month =month+currMonth-selectMonth;
		if(currDay-selectDay < 0){
			month -=1;
		}
		
		if(input_date > new Date()){
			alert("根据您选的宝宝生日计算您的宝宝现在还没出生，请重新选择宝宝生日！");
			return ;
		}
		if(input_date.toLocaleDateString().toString() == (new Date()).toLocaleDateString().toString()){
			if(confirm("你选择的宝宝生日是今天的时间，确认吗？")){
				window.open("http://abc.yaolan.com/ceshi/babytest.action?birthday=" + document.getElementById("year_date").value + "-" + document.getElementById("month_date").value + "-" + document.getElementById("day_date").value+"&from=");			
			}			
		}else if(month > 72){
			alert("选择宝宝生日不能超过6岁，请重新选择！");
			return ;
		}else{
			window.open("http://abc.yaolan.com/ceshi/babytest.action?birthday=" + document.getElementById("year_date").value + "-" + document.getElementById("month_date").value + "-" + document.getElementById("day_date").value+"&from=");
		}
	}else if(flag==4){
		window.open("http://abc.yaolan.com/ceshi/babytest.action?from="+from);
		
	}else if(flag==5){
		window.open("http://abc.yaolan.com/app/ceshi/babytest.action?birthday="+document.getElementById("year_date").value + "-" + document.getElementById("month_date").value + "-" + document.getElementById("day_date").value+"&from="+from);
	}else if(flag == 6) {
		var input_date_str = document.getElementById("year_date2").value + "-" + document.getElementById("month_date2").value + "-" + document.getElementById("day_date2").value+"&from="+from;
		var input_date = Date.parse(input_date_str);
		{
			window.open("http://abc.yaolan.com/ceshi/babytest.action?birthday=" + input_date_str+"&from="+from);
		}
		
	}else {//如果是注册用户
		window.open("http://abc.yaolan.com/ceshi/babytest.action?from="+from);
	}
}
